//
// Created by wujehy on 2020/6/22.
//

#include <iostream>
#include "MysqlDB.h"

int MysqlDB::initDataBase()
{
    std::cout<<" MysqlDB::initDataBase : enter ... " <<std::endl;
    std::cout <<" this is MysqlDB Database Test "<<std::endl;
    return 0;
}

int MysqlDB::Insert(std::string key, std::string value)
{
    std::cout<<" MysqlDB::Insert : enter ... " <<std::endl;
    auto pt = KV_map.insert(std::pair<std::string , std::string >(key , value));
    if (pt.second)
    {
        return 0;
    } else{
        return -1;
    }
}

int MysqlDB::Select(std::string key,std::string &output_value)
{
    std::cout<<" MysqlDB::Select : enter ... " <<std::endl;

    auto find = KV_map.find(key);
    if (find != KV_map.end())
    {
        output_value = find->second;
        return 0;
    }
    return -1;
}

int MysqlDB::Delete(std::string key)
{
    std::cout<<" MysqlDB::Delete : enter ... " <<std::endl;

    auto find = KV_map.find(key);
    if (find != KV_map.end())
    {
        KV_map.erase(find);
        return 0;
    }
    return -1;
}
